﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.DataControls;

public partial class EmailRestrictions : Acms.AcmsControls.ContentControls.Admin.BaseCustomAdminControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ds_Select(object sender, EventDrivenDataSourceSelectEventArgs e)
    {
        CarbonExchange.Bll.EmailRestrictionFactory factory = new CarbonExchange.Bll.EmailRestrictionFactory();
        e.SetData(factory.GetAllBySiteId(AcmsContext.SiteId));
    }

    protected void ds_Delete(object sender, EventDrivenDataSourcePerformOperationEventArgs e)
    {
        int id = (int)e.Keys["Id"];
        CarbonExchange.Bll.EmailRestrictionFactory factory = new CarbonExchange.Bll.EmailRestrictionFactory();
        CarbonExchange.Bll.EmailRestriction tmp = factory.GetById(id);
        if (tmp != null)
        {
            factory.Delete(tmp);
        }
    }

    protected void ds_Insert(object sender, EventDrivenDataSourcePerformOperationEventArgs e)
    {
        if (Page.IsValid)
        {
            CarbonExchange.Bll.EmailRestrictionFactory factory = new CarbonExchange.Bll.EmailRestrictionFactory();
            CarbonExchange.Bll.EmailRestriction tmp = new CarbonExchange.Bll.EmailRestriction(AcmsContext.SiteId);
            tmp.Access = (bool)e.NewValues["Access"];
            tmp.EmailFilter = (string)e.NewValues["EmailFilter"];
            factory.Save(tmp);
            e.RowsChanged = 1;
        }
    }

    protected void ds_Update(object sender, EventDrivenDataSourcePerformOperationEventArgs e)
    {
        if (Page.IsValid)
        {
            int id = (int)e.Keys["Id"];
            CarbonExchange.Bll.EmailRestrictionFactory factory = new CarbonExchange.Bll.EmailRestrictionFactory();
            CarbonExchange.Bll.EmailRestriction tmp = factory.GetById(id);
            if (tmp != null)
            {
                tmp.Access = (bool)e.NewValues["Access"];
                tmp.EmailFilter = (string)e.NewValues["EmailFilter"];
                factory.Save(tmp);
                e.RowsChanged = 1;
            }
        }
    }

}
